﻿#include "setup7wind.h"
#include "ui_setup7wind.h"
#include <mainwindow.h>
#include "mainwindow.h"
extern intListener doorStatus;
setup7wind::setup7wind(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::setup7wind)
{
    ui->setupUi(this);
    connect(&doorStatus, &intListener::valueChanged,this,&setup7wind::doorStatusChanged,Qt::QueuedConnection);
}
void setup7wind::doorStatusChanged(){
    if(doorStatus.get()==0)
    {
        ui->pushButton_9->setText("        打开仓门");
    }
    else
    {
        ui->pushButton_9->setText("        关闭仓门");
    }
}
setup7wind::~setup7wind()
{
    delete ui;
}
void setup7wind::showEvent(QShowEvent *event)
{
    tcpClient = TcpClient::getInstance();
    if(doorStatus.get()==0)
    {
        ui->pushButton_9->setText("        打开仓门");
    }
    else
    {
        ui->pushButton_9->setText("        关闭仓门");
    }
    event->accept();
}
void setup7wind::on_returnBtn_clicked()
{
    this->close();
    emit changeTotalWindow();
}


void setup7wind::on_SaveBtn_2_clicked()
{
    this->close();
    emit changeTotalWindow();
}


void setup7wind::on_pushButton_9_clicked()
{
    if(doorStatus.get()==0)
    {
        doorStatus.set(1);
        ui->pushButton_9->setText("        关闭仓门");
    }
    else
    {
        doorStatus.set(0);
        ui->pushButton_9->setText("        打开仓门");
    }
}


void setup7wind::on_comboBox_2_currentTextChanged(const QString &arg1)
{
//    if(arg1=="打开"){
//        MainWindow::speechflagkg.set(0);
//        qDebug()<<"打开串口";
//    }else if(arg1=="关闭"){
//        MainWindow::speechflagkg.set(1);
//        qDebug()<<"关闭串口";
//    }
}

void setup7wind::on_SaveBtn_clicked()
{
//    qDebug()<<ui->comboBox_2->currentText();
    if(ui->comboBox_2->currentText()=="打开"){
        MainWindow::speechflagkg.set(0);
        qDebug()<<"打开串口";
    }else if(ui->comboBox_2->currentText()=="关闭"){
        MainWindow::speechflagkg.set(1);
        qDebug()<<"关闭串口";
        qDebug()<<MainWindow::speechflagkg.get();
    }
    QMessageBox::information(nullptr, "提示", "保存成功");

}
